import requests

class SendMethod:

    @staticmethod
    def send_method(method, url, params=None,data=None):
        #发送请求
        if method == 'get':
            respone=requests.get(url=url,params=params)
        elif method =='post':
            respone=requests.post(url=url,data=data)
        else:
            respone=None
            print("请求结果错误请重新输入")

        #获取请求
        result={}#将响应结果放入字典中
        if respone is not None:#判断respone是否为空
            result['status_code']=respone.status_code #获得响应状态码
            result['headers']=respone.headers#获取响应头
            result['body']=respone.json()#获取响应体
            result['respone_time']=int(respone.elapsed.microseconds /1000)#获得响应时间
            return result
        else:
            return respone



if __name__ == '__main__':
    method='post'
    url='http://127.0.0.1:8000/api/add_event/'
    data={
        "eid": '70',
        "name": "iPhone21发布会",
        "limit": '200',
        "status": "0",
        "address": "汤臣一品",
        "start_time": "2022-10-23"
    }

    method1='get'
    url1='http://www.baibu.com'
    params={"wd":"武汉天气"}
    # print(SendMethod.send_method(method1, url1, params=params))
    print(SendMethod.send_method(method, url, data=data))





